import requests


class SendMethod:
    @staticmethod
    def send_method(method, url, params=None, data=None):
        if method == 'post':
            response = requests.post(url=url, data=data)
        elif method == 'get':
            response = requests.get(url=url, params=params)
        else:
            response = None
            print('请求方式错误')
        result = {}
        if response is not None:

            result['status_codes'] = response.status_code
            result['headers'] = response.headers
            result['body'] = response.json()
            result['response_time'] = int(response.elapsed.microseconds / 1000)
            return result

        else:
            return response


if __name__ == '__main__':
    #  请求行
    url = "http://127.0.0.1:8000/api/add_event/"
    #  请求体
    body = {
        "eid": "521555",
        "name": "爱拼才会赢ya",
        "limit": "20",
        "status": "1",
        "address": "武汉源码时代",
        "start_time": "2022-07-25"
    }
    sm = SendMethod.send_method("post", url, data=body)
    print(sm)
